package com.lenovo.leos.letools.utils;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.util.Log;

public class StreamTool {
	private static int currentlen;
	/**
	 * @param in
	 * @return
	 * @throws IOException
	 * 将较小的数据文件，通过此方法将流转换成byte数组
	 */
	public static byte[] getByteData(InputStream in) throws IOException{
		byte[] buffer = new byte[1024];
		int len = -1;
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		while((len=in.read(buffer))!=-1){
			bos.write(buffer,0, len);
		}
		return bos.toByteArray();
	}
	/**
	 * @param in
	 * @return 解析每次HTTP请求返回的流信息
	 */
	public static String parseStream(InputStream in) {
		byte[] retValue = null;
		try {
			retValue = StreamTool.getByteData(in);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return new String(retValue);
	}
}
